package com.itic.mall.system.msg.type.service;

import com.itic.appbase.framework.common.constants.DBConst;
import com.itic.appbase.framework.common.service.CrudService;
import com.itic.mall.system.inter.msg.type.persistence.dao.MsgTypeDao;
import com.itic.mall.system.inter.msg.type.persistence.model.MsgType;
import com.itic.mall.system.inter.msg.type.persistence.model.MsgTypeExample;
import com.itic.mall.system.inter.msg.type.persistence.model.MsgTypeExample.Criteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
@Transactional
public class MsgTypeService
     extends CrudService<MsgTypeDao,MsgType,MsgTypeExample> {
    @Autowired
    private MsgTypeDao msgTypeDao;

    
    public MsgType getMsgTypeByType(String type) {
    	MsgTypeExample example = new MsgTypeExample();
    	Criteria criteria = example.createCriteria();
    	criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    	criteria.andTypeEqualTo(type);
    	List<MsgType> msgTypes = this.list(example);
    	MsgType msgType = msgTypes.isEmpty()?null:msgTypes.get(0);
    	return msgType;
    }
    
    public List<MsgType> getMsgTypeByParentId(String parentId){
    	MsgTypeExample example = new MsgTypeExample();
    	Criteria criteria = example.createCriteria();
    	criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    	criteria.andParentIdEqualTo(parentId);
    	List<MsgType> msgTypes = this.list(example);
    	return msgTypes;
    }
    
    public List<MsgType> getParentMsgType(){
    	MsgTypeExample example = new MsgTypeExample();
    	Criteria criteria = example.createCriteria();
    	criteria.andIsEffectiveEqualTo(DBConst.TRUE);
    	criteria.andParentIdIsNull();
    	List<MsgType> msgTypes = this.list(example);
    	return msgTypes;
    }

}